home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 January / Disc 3 / Amethyst.iso / live / usr / lib / rpm-3.0.6 / vpkg-provides.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2001-04-06  |  8.2 KB  |  358 lines

  1. #!/bin/sh
  2.  
  3. #
  4. # Original Author: Tim Mooney (mooney@plains.NoDak.edu)
  5. # Improvements by: Ken Estes <kestes@staff.mail.com>
  6. # This file is distributed under the terms of the GNU General Public License
  7. #
  8. # vpkg-provides.sh is part of RPM, the Red Hat Package Manager.
  9. # vpkg-provides.sh searches a list of directories (based on what OS it's
  10. # being executed on) for shared libraries and interpreters that have been
  11. # installed by some packaging system other than RPM.  It then generates a
  12. # spec file that can be used to build a "virtual package" that provides all
  13. # of these things without actually installing any files.  This makes it much
  14. # easier to use RPM on non-Linux systems.
  15. #
  16. # Comments: This script is a quick hack.  A better solution is to use the
  17. # vendor's package management commands to actually query what's installed, and
  18. # build one or more spec files based on that.  This is something
  19. # I intend to write, probably in perl, but the need for something like this
  20. # first effort was great, so I didn't want to wait until the better solution
  21. # was done.
  22.  
  23. # you will need to create a spec_header for the virtual package.  This
  24. # header will provide such specfile information as:
  25. #
  26. #  Summary: 
  27. #  Name: 
  28. #  Version: 
  29. #  Release: 
  30. #  Copyright: 
  31. #  Group: 
  32. #  Source: 
  33.  
  34.  
  35. usage= "usage: $0 [--spec_header '/path/to/os-base-header.spec'] \n"
  36. usage= "$usage\t[--find_provides '/path/to/find-provides']\n"
  37. usage= "$usage\t[--shlib_dirs 'dirs:which:contain:shared:libs']\n"
  38. usage= "$usage\t[--ignore_dirs 'egrep|pattern|of|paths|to|ignore']\n"
  39.  
  40. # these two should be unnessary as the regular dependency analysis
  41. # should take care of interpreters as well as shared libraries.
  42.  
  43. usage= "$usage\t[--interp_dirs 'dirs:which:contain:interpreters']\n"
  44. usage= "$usage\t[--interps 'files:to:assume:are:installed']\n"
  45.  
  46.  
  47. # this command may not be portable to all OS's, does something else
  48. # work? can this be set in the case $osname statement?
  49.  
  50. sum_cmd="xargs cksum"
  51.  
  52. date=`date`
  53. hostname=`uname -n`
  54.  
  55. # if some subdirectories of the system directories needs to be ignored
  56. # (eg /usr/local is a subdirectory of /usr but should not be part of
  57. # the virtual package) then call this script with IGNORE_DIRS set to a
  58. # vaild egrep pattern which discribes the directories to ignored.
  59.  
  60. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bsd
  61. export PATH
  62.  
  63.  
  64. #
  65. # The (OS independent) default values.
  66. #
  67. spec_header='/usr/lib/rpm/os-base-header.spec';
  68. interps="sh:csh:ksh:dtksh:wish:tclsh:perl:awk:gawk:nawk:oawk"
  69. find_provides='/usr/lib/rpm/find-provides';
  70. ignore_dirs="."
  71.  
  72.  
  73. osname=`uname -s`
  74. if test $? -ne 0 || test X$osname = X ; then
  75.     echo "I can't determine what platform this is.  Exiting"
  76.     exit 1
  77. fi
  78.  
  79.  
  80. #
  81. # Set OS dependent defaults
  82. #
  83. case $osname in
  84.     OSF1)
  85.         shlib_dirs='/shlib:/usr/shlib:/usr/dt/lib:/usr/opt'
  86.         interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/bin/posix'
  87.         ;;
  88.     HP-UX)
  89.         shlib_dirs='/usr/shlib:/usr/dt/lib:/opt'
  90.         shlib_dirs="$shlib_dirs:/usr/bms:/usr/obam:/usr/sam"
  91.         interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/bin/posix'
  92.         ;;
  93.     AIX)
  94.         shlib_dirs='/usr/lib:/usr/ccs/lib:/usr/dt/lib:/usr/lpp:/usr/opt'
  95.         interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin'
  96.         ;;
  97.     SunOS)
  98.         shlib_dirs='/etc/lib:/etc/vx:/opt:/usr/lib:/usr/ccs/lib:/usr/dt/lib'
  99.         shlib_dirs="$shlib_dirs:/usr/4lib:/usr/openwin/lib:/usr/snadm/lib"
  100.         shlib_dirs="$shlib_dirs:/usr/ucblib:/usr/xpg4/lib"
  101.         interp_dirs='/bin:/usr/bin:/sbin:/usr/dt/bin:/usr/xpg4/bin'
  102.         ;;
  103.     IRIX|IRIX64)
  104.         shlib_dirs='/lib:/usr/lib:/usr/lib32:/usr/lib64'
  105.         # Irix always makes me laugh...
  106.         shlib_dirs="$shlib_dirs:/usr/ToolTalk:/usr/xfsm:/usr/SpeedShop"
  107.         shlib_dirs="$shlib_dirs:/usr/sgitcl:/usr/SGImeeting:/usr/pcp/lib"
  108.         shlib_dirs="$shlib_dirs:/usr/Motif-2.1"
  109.         interp_dirs='/bin:/usr/bin:/sbin:/usr/sbin:/usr/dt/bin'
  110.         ;;
  111.     *)
  112.         echo "I'm sorry.  I haven't been configured yet to work on $osname."
  113.         echo "Please poke around your system and try figure out what directories"
  114.         echo "I should be searching for shared libraries.  Once you have this"
  115.         echo "information, email it to rpm-list@redhat.com, so that your OS"
  116.         echo "will be supported by some future version of this script."
  117.         echo ""
  118.         echo "Thanks!"
  119.         echo
  120.         exit 2
  121.         ;;
  122. esac
  123.  
  124.  
  125. # allow the user to change defaults with the command line arguments.
  126.  
  127. # Loop over all args
  128.  
  129. while :
  130. do
  131.  
  132. # Break out if there are no more args
  133.     case $# in
  134.     0)
  135.         break
  136.         ;;
  137.     esac
  138.  
  139. # Get the first arg, and shuffle
  140.     option=$1
  141.     shift
  142.  
  143. # Make all options have two hyphens
  144.     orig_option=$option    # Save original for error messages
  145.     case $option in
  146.     --*) ;;
  147.     -*) option=-$option ;;
  148.     esac
  149.  
  150.  
  151.     case $option in
  152.     --spec_header)
  153.         spec_header=$1
  154.         shift
  155.         ;;
  156.     --ignore_dirs)
  157.         ignore_dirs=$1
  158.         shift
  159.         ;;
  160.     --find_provides)
  161.         find_provides=$1
  162.         shift
  163.         ;;
  164.     --shlib_dirs)
  165.         shlib_dirs=$1
  166.         shift
  167.         ;;
  168.     --interp_dirs)
  169.         interp_dirs=$1
  170.         shift
  171.         ;;
  172.     --interps)
  173.         interps=$1
  174.         shift
  175.         ;;
  176.     --help)
  177.         echo $usage
  178.         exit 0
  179.         ;;
  180.     *)
  181.         echo "$0: Unrecognized option: \"$orig_option\"; use --help for usage." >&2
  182.         exit 1
  183.         ;;
  184.     esac
  185. done
  186.  
  187.  
  188. # consistancy checks on the arguments
  189.  
  190. if [ ! -f $spec_header ]; then
  191.     echo "You must pass me the full path to the partial spec file"
  192.     echo "as my first argument, since this file does not appear in the"
  193.     echo "default location of $default_spec_header"
  194.     echo
  195.     echo $usage
  196.     echo
  197.     exit 9
  198. fi
  199.  
  200.  
  201. if [ ! -f $find_provides ]; then
  202.     echo "You must pass me the full path to the find-provides script as my"
  203.     echo "second argument, since find-provides does not appear in the"
  204.     echo "default location of $default_find_provides"
  205.     echo
  206.     echo $usage
  207.     echo
  208.     exit 9
  209. fi
  210.  
  211.  
  212.  
  213. provides_tmp=/tmp/provides.$$
  214. if test -f $provides_tmp ; then
  215.     echo "$provides_tmp already exists.  Exiting."
  216.     exit 11
  217. fi
  218.  
  219. #
  220. # iterate through all the directories in shlib_dirs, looking for shared
  221. # libraries
  222. #
  223. for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
  224. do
  225.     find $d -type f -print 2>/dev/null | egrep -v \'$IGNORE_DIRS\' | $find_provides >> $provides_tmp
  226. done
  227.  
  228. sum_tmp=/tmp/sum.$$
  229. if test -f $sum_tmp ; then
  230.     echo "$sum_tmp already exists.  Exiting."
  231.     exit 11
  232. fi
  233.  
  234. #
  235. # iterate through all the directories in shlib_dirs, record the sum
  236. #
  237. for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
  238. do
  239.     find $d -type f -print 2>/dev/null | egrep -v \'$IGNORE_DIRS\' | $sum_cmd >> $sum_tmp
  240. done
  241.  
  242.  
  243. #
  244. # output the initial part of the spec file
  245. #
  246. cat $spec_header
  247.  
  248. #
  249. # Output the shared libraries
  250. #
  251. {
  252.     for f in `cat $provides_tmp | sort -u`
  253.     do
  254.     echo "Provides: $f"
  255.     done
  256.  
  257. #
  258. # Output the available shell interpreters
  259. #
  260.     for d in `echo $interp_dirs | sed -e 's/:/ /g'`
  261.     do
  262.     for f in `echo $interps | sed -e 's/:/ /g'`
  263.     do
  264.         if test -f $d/$f ; then
  265.             echo "Provides: $d/$f"
  266.         fi
  267.     done
  268.     done
  269. } | sed -e 's/%/%%/g'
  270.  
  271. #
  272. # Output the discription of the spec file
  273. #
  274.  
  275. cat <<_EIEIO_
  276.  
  277.  
  278. %description
  279. This is a virtual RPM package.  It contains no actual files.  It uses the
  280. \`Provides' token from RPM 3.x and later to list many of the shared libraries
  281. and interpreters that are part of the base operating system and associated
  282. subsets for $osname.
  283.  
  284. This virtual package was constructed based on the vendor/system software
  285. installed on the $osname machine named $hostname, as of the date
  286. $date.
  287.  
  288. _EIEIO_
  289.  
  290. #
  291. # Output the build sections of the spec file
  292. #
  293. echo '%prep'
  294. echo '# nothing to do'
  295. echo '%build'
  296. echo '# nothing to do'
  297. echo '%install'
  298. echo '# nothing to do'
  299. echo '%clean'
  300. echo '# nothing to do'
  301.  
  302. #
  303. # Output the verify section of the spec file
  304. #
  305.  
  306. cat <<_EIEIO_
  307.  
  308. %verifyscript
  309.  
  310. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/ucb:/usr/bsd
  311. export PATH
  312.  
  313. sum_current_tmp=/tmp/rpm.sum.current.\$\$
  314. if test -f \$sum_current_tmp ; then
  315.     echo "\$sum_current_tmp already exists.  Exiting."
  316.     exit 11
  317. fi
  318.  
  319. sum_package_tmp=/tmp/rpm.sum.package.\$\$
  320. if test -f \$sum_package_tmp ; then
  321.     echo "\$sum_package_tmp already exists.  Exiting."
  322.     exit 11
  323. fi
  324.  
  325. for d in `echo $shlib_dirs | sed -e 's/:/ /g'`
  326. do
  327.     find \$d -type f -print 2>/dev/null | egrep -v \'$IGNORE_DIRS\' | $sum_cmd >> \$sum_current_tmp
  328. done
  329.  
  330. cat >\$sum_package_tmp <<_EOF_
  331. _EIEIO_
  332.  
  333. # the contents of the temporary file are hardcoded into the verify
  334. # script so that the file can be reproduced at verification time.
  335.  
  336. cat $sum_tmp | sed -e 's/%/%%/g'
  337.  
  338. cat <<_EIEIO_
  339. _EOF_
  340.  
  341.  
  342. cmp \$sum_package_tmp \$sum_current_tmp 
  343.  
  344. if [ $? -ne 0 ]; then
  345.     echo "Differences found by: cmp \$sum_package_tmp \$sum_current_tmp"
  346.     exit \$?
  347. fi
  348.  
  349. _EIEIO_
  350.  
  351. #
  352. # Output the files section of the spec file
  353. #
  354.  
  355. echo '%files'
  356. echo '# no files in a virtual package'
  357.